package cn.akwangl.springbootdev;

import cn.akwangl.springbootdev.enums.ErrorEnum;
import cn.akwangl.springbootdev.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result implements Serializable {

    private int code;
    private String msg;
    private Object date;


    public Result(ErrorEnum errorEnum) {
        this.code = errorEnum.getCode();
        this.msg = errorEnum.getMsg();
    }

    public Result(ServiceException e) {
        this.code = e.getCode();
        this.msg = e.getMsg();
    }

    public static Result error() {
        return new Result(ErrorEnum.ERROR);
    }


}
